<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    
<script>
    // 方式一，通过函数返回对象
    function createPerson(name) {
        const obj = {}
        obj.name = name
        obj.introduceSelf = function() {
            console.log(`你好！我是 ${this.name}。`)
        }
        return obj
    }

    let p = createPerson("Alice")
    p.introduceSelf()
    

    // 方式二，通过构造函数创建对象

    function Person(name) {
        this.name = name
        this.introduceSelf = function() {
            console.log(`你好！我是 ${this.name}。`)
        }
    }

    let np = new Person("Bob")
    np.introduceSelf()
</script>

</body>
</html>